import {defineStore} from "pinia"
import {ref} from "vue"

export const useLoadingStore = defineStore('loadingStore', () => {
  // 是否开启加载
  const isLoading = ref(false)
  /**
   * 获取是否开启加载
   */
  const getIsLoading = () => {
    return isLoading.value
  }
  /**
   * 开启加载
   */
  const loading = () => {
    isLoading.value = true
  }
  /**
   * 加载结束
   */
  const loaded = () => {
    isLoading.value = false
  }

  // 加载描述信息
  const loadingDesc = ref('加载中...')
  /**
   * 获取加载描述信息
   */
  const getLoadingDesc = () => {
    return loadingDesc.value
  }
  /**
   * 设置加载描述信息
   */
  const setLoadingDesc = (desc: string) => {
    loadingDesc.value = desc
  }

  return {
    getIsLoading,
    loading,
    loaded,
    getLoadingDesc,
    setLoadingDesc,
  }
})
